package org.lq.ht.view.room;

import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import org.lq.ht.entity.Customer;
import org.lq.ht.entity.Dictionary;
import org.lq.ht.entity.TypeID;
import org.lq.ht.service.impl.DictionaryServiceImpl;
import org.lq.ht.util.CastUtils;

import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import com.eltima.components.ui.DatePicker;
import javax.swing.JRadioButton;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.text.ParseException;
import java.util.List;
import java.awt.event.ActionEvent;

public class AddCustomer2 extends JPanel {
	private JTextField txt_name;
	private JTextField txt_charge;
	private JTextField txt_phone;
	private JTextField txt_note;
	private JTextField txt_address;
	private JTextField txt_cardId;
	private JComboBox cb_roomType;
	private JComboBox vip_level;
	private JRadioButton radio_boy;
	private JRadioButton radio_gril;
	private DatePicker dp2_leave;
	private JButton btn_saveCustomer;
	private JButton btn_cancel;
	private DatePicker dp_stayin;
	
	public JComboBox getCb_roomType() {
		return cb_roomType;
	
	}
	/**
	 * Create the panel.
	 */
	public AddCustomer2() {
		setLayout(null);
		
		JPanel contentPane = new JPanel();
		contentPane.setLayout(null);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setBounds(24, 36, 470, 614);
		add(contentPane);
		
		JLabel lblNewLabel = new JLabel("姓 名:");
		lblNewLabel.setBounds(78, 48, 58, 15);
		contentPane.add(lblNewLabel);
		
		txt_name = new JTextField();
		txt_name.setColumns(10);
		txt_name.setBounds(174, 40, 128, 23);
		contentPane.add(txt_name);
		
		JLabel lblNewLabel_1 = new JLabel("姓 别:");
		lblNewLabel_1.setBounds(78, 94, 58, 15);
		contentPane.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("房间类型");
		lblNewLabel_2.setBounds(78, 186, 58, 15);
		contentPane.add(lblNewLabel_2);
		
		cb_roomType = new JComboBox();
		cb_roomType.setBounds(174, 182, 128, 22);
		contentPane.add(cb_roomType);
		
		JLabel lblNewLabel_2_2 = new JLabel("其中房费");
		lblNewLabel_2_2.setBounds(78, 237, 58, 15);
		contentPane.add(lblNewLabel_2_2);
		
		JLabel lblNewLabel_2_4 = new JLabel("会员卡级别");
		lblNewLabel_2_4.setBounds(78, 287, 74, 18);
		contentPane.add(lblNewLabel_2_4);
		
		JLabel lblNewLabel_2_5 = new JLabel("地址");
		lblNewLabel_2_5.setBounds(78, 330, 74, 23);
		contentPane.add(lblNewLabel_2_5);
		
		JLabel lblNewLabel_2_6 = new JLabel("入住时间");
		lblNewLabel_2_6.setBounds(78, 374, 58, 15);
		contentPane.add(lblNewLabel_2_6);
		
		JLabel lblNewLabel_2_7 = new JLabel("联系电话");
		lblNewLabel_2_7.setBounds(78, 457, 58, 15);
		contentPane.add(lblNewLabel_2_7);
		
		JLabel lblNewLabel_2_8 = new JLabel("预计离店时间");
		lblNewLabel_2_8.setBounds(78, 415, 74, 23);
		contentPane.add(lblNewLabel_2_8);
		
		txt_charge = new JTextField();
		txt_charge.setColumns(10);
		txt_charge.setBounds(174, 233, 128, 23);
		contentPane.add(txt_charge);
		
		vip_level = new JComboBox();
		vip_level.setBounds(174, 283, 128, 22);
		contentPane.add(vip_level);
		
		dp_stayin = new DatePicker();
		dp_stayin.setBounds(174, 372, 128, 19);
		contentPane.add(dp_stayin);
		
		JLabel lblNewLabel_3 = new JLabel("身份证号:");
		lblNewLabel_3.setBounds(78, 143, 58, 15);
		contentPane.add(lblNewLabel_3);
		
		txt_phone = new JTextField();
		txt_phone.setColumns(10);
		txt_phone.setBounds(174, 454, 128, 21);
		contentPane.add(txt_phone);
		
		JLabel lblNewLabel_4 = new JLabel("备注");
		lblNewLabel_4.setBounds(78, 514, 58, 21);
		contentPane.add(lblNewLabel_4);
		
		txt_note = new JTextField();
		txt_note.setColumns(10);
		txt_note.setBounds(174, 514, 128, 21);
		contentPane.add(txt_note);
		
		txt_address = new JTextField();
		txt_address.setColumns(10);
		txt_address.setBounds(174, 332, 128, 19);
		contentPane.add(txt_address);
		
		txt_cardId = new JTextField();
		txt_cardId.setColumns(10);
		txt_cardId.setBounds(174, 140, 128, 23);
		contentPane.add(txt_cardId);
		
		dp2_leave = new DatePicker();
		dp2_leave.setBounds(174, 416, 128, 21);
		contentPane.add(dp2_leave);
		
		radio_boy = new JRadioButton("男");
		radio_boy.setBounds(175, 90, 58, 19);
		contentPane.add(radio_boy);
		
		radio_gril = new JRadioButton("女");
		radio_gril.setBounds(235, 90, 127, 23);
		contentPane.add(radio_gril);
		
		btn_saveCustomer = new JButton("保存客户信息");
		btn_saveCustomer.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		btn_saveCustomer.setBounds(99, 558, 116, 35);
		contentPane.add(btn_saveCustomer);
		
		btn_cancel = new JButton("取消");
		btn_cancel.setBounds(243, 558, 105, 35);
		contentPane.add(btn_cancel);
		inintCombox();

	}
	public void inintCombox() {
		DictionaryServiceImpl dsi = new DictionaryServiceImpl();
		List<Dictionary> roomType = dsi.findDictionaryByTypeID(TypeID.房间类型);
		List<Dictionary> vipLevelList = dsi.findDictionaryByTypeID(TypeID.会员级别);
		Dictionary d = new Dictionary();
		d.setNo(-1);
		d.setName("-----请选择----");
		d.setType_id(TypeID.默认.getId());
		roomType.add(0,d);
		vipLevelList.add(0,d);
		Dictionary[] type_room = roomType.toArray(new Dictionary[] {});
		Dictionary[] vip_dic = vipLevelList.toArray(new Dictionary[] {});
		DefaultComboBoxModel<Dictionary> roomDic = new DefaultComboBoxModel<Dictionary>(type_room);
		DefaultComboBoxModel<Dictionary> vipDic = new DefaultComboBoxModel<Dictionary>(vip_dic);
		cb_roomType.setModel(roomDic);
		vip_level.setModel(vipDic);
		
	}
	public Customer add() {
		Customer c = new Customer();
		c.setName(txt_name.getText());
		c.setAddress(txt_address.getText());
		try {
			c.setCome_date(CastUtils.utilDateToSqlTimestamp(CastUtils.parse(dp_stayin.getInnerTextField().getText())));
			c.setLeave_date(CastUtils.utilDateToSqlTimestamp(CastUtils.parse(dp2_leave.getInnerTextField().getText())));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		Object obj = vip_level.getSelectedItem();
		Dictionary d = (Dictionary) obj;
		c.setCard(d.getNo());
		if(radio_boy.isSelected()) {
			c.setGender("男");
		}else {
			c.setGender("女");
		}
		c.setNote(txt_note.getText());
		c.setPhone_num(CastUtils.castInt(txt_phone.getText()));
		c.setRoom_price(CastUtils.castDouble(txt_charge.getText()));
		Object obj2 = cb_roomType.getSelectedItem();
		Dictionary d2 = (Dictionary)obj2;
		c.setRoom_type(d2.getNo());
		c.setId(CastUtils.castInt(txt_cardId.getText()));
		if(d.getNo()>0) {
			c.setVip_status(1);//1代表是会员0代表普通顾客
		}else {
			c.setVip_status(0);
		}
		return c;	
	}

}
